﻿// See https://aka.ms/new-console-template for more information

using System.Text;
using Medallion.Threading.Redis;
using RabbitMQ.Client;
using StackExchange.Redis;

  Console.WriteLine("Hello, World!");


  var factory = new ConnectionFactory() { HostName = "192.168.139.121", UserName = "admin" ,Password = "admin"};
  using(var connection = factory.CreateConnection())
  using(var channel = connection.CreateModel())
  {
    // channel.QueueDeclare(queue: "hello",
    //   durable: false,
    //   exclusive: false,
    //   autoDelete: false,
    //   arguments: null);
    //
    string message = "Hello World!";
    var body = Encoding.UTF8.GetBytes(message);
    //
    // channel.BasicPublish(exchange: "",
    //   routingKey: "hello",
    //   basicProperties: null,
    //   body: body);

    IBasicProperties properties = null;
    if (properties == null)
    {
      properties = channel.CreateBasicProperties();
      properties.DeliveryMode =1;
    }

    if (string.IsNullOrEmpty(properties.MessageId))
    {
      properties.MessageId = Guid.NewGuid().ToString("N");
    }

  //  SetEventMessageHeaders(properties, headersArguments);

    channel.BasicPublish(
      exchange: "test",
      routingKey: "eventName",
      mandatory: true,
      basicProperties: properties,
      body: body
    );
    
    
    Console.WriteLine(" [x] Sent {0}", message);
  }

  Console.WriteLine(" Press [enter] to exit.");
  Console.ReadLine();
//
// string m = "123";
// var connectionString = "192.168.139.122:6379,defaultDatabase=1,,password=admin123";
// var connection = await ConnectionMultiplexer.ConnectAsync(connectionString); // uses StackExchange.Redis
// var @lock = new RedisDistributedLock("MyLockName", connection.GetDatabase());
// await using (var handle = await @lock.TryAcquireAsync())
// {
//     if (handle != null)
//     { 
//         await Task.Delay(5000);
//         m = "456";
//         Console.WriteLine("abc");
//         
//     }
// }
//
// Console.WriteLine(m);